<template>
  <div>
    <top-header :isLeft="true" title="地址管理"></top-header>
    <div class="header">
      <div class="header-left">
      <p>当前定位</p>
      </div>
      <div class="header-right" @click="addAddress()"><a-icon type="plus" />新增地址</div>
    </div>
    
    <div class="banner">
      <div class="banner-left">
      <p>塘西</p>
      <p>各地商品和配送时效不同，请准确选择地址</p>
      </div>
      <div class="banner-right">
        <a-icon class="banner-icon" type="redo" />重新定位
      </div>
    </div>

    <p style="color:gray;margin: 10px 0;">我的收获地址</p>

    <div class="no-address" v-if="commonAddress.length == 0">
      <p>暂无收货地址</p>
    </div>
    
    <div class="common-address" v-else>
      <ul>
        <li v-for="(item, index) in commonAddress" :key="index">
          <p @click="changeAddress(item.address_location)">
            <b>{{ item.address_location }}{{ item.address_doorplate }}</b>
            <a-tag color="cyan">{{ labelMap[item.label] }}</a-tag>
          </p>
          <p>{{ item.user_name }}&nbsp;{{ item.user_phone }}</p>
        </li>
      </ul>
    </div>

    <p style="color:gray;margin: 10px 0;">附近地址</p>
    <div class="fox">
       <div class="foot" v-for="(item,index) in addressList" :key="index">
      <span @click="changeAddress(item.name)">{{item.name}}</span>
      <hr>
    </div>
    </div>
  
  </div>
</template>

<script>
import TopHeader from "../components/TopHeader.vue";
export default {
  components: {
    TopHeader,
  },
  data() {
    return {
      tempAddress: {
        user_name: "",
        user_phone: "",
        address_location: "",
        address_doorplate: "",
        label: "1",
      },
      labelMap: {},
      addressList:[
        {
          name:'塘西'
        },
        {
          name:'漳河口派出所'
        },
        {
          name:'芜湖市公安局弋江分局战巡基地'
        },
        {
          name:'芜湖市公安局弋江分局巡逻警察大队'
        },
        {
          name:'安徽信息工程学院(文津校区)'
        },
        {
          name:'芦花塘'
        },
        {
          name:'安徽信息工程学院(文津校区)西2教学楼'
        },
        {
          name:'丁村'
        },
        {
          name:'安徽工程大学机电学院西1号楼'
        },
        {
          name:'皖南医学院(滨江校区)'
        },
        {
          name:'澛港新区三期五区15-1栋'
        },
        {
          name:'芜湖市公安局弋江区分局高校园区派出所警务室'
        }

      ]
    };
  },
  computed: {
    commonAddress() {
      return this.$store.getters.commonAddress;
    },
    currentAddress(){
      return this.$store.getters.currentAddress;
    }
  },
   methods: {
     changeAddress(name){
       this.$store.dispatch('setCurrentAddress',name);
       this.$router.push({name:'Home'});
     },
    addAddress() {
      //把记录表单的数据传到vuex中
      this.$store.dispatch('setTempAddress',this.tempAddress);
      //把页面跳转到新建地址页面
      this.$router.push({name:'AddAddress'});
    },
  },
  mounted() {
    const self = this;
    this.$http.get('/api/labelMap').then(
    res => {
      self.labelMap = res.data.data.data;
    },
    err => {

    })
  },
};
</script>
<style lang="scss" scoped>
.header {
  display: flex;
  justify-content: space-between;
}
.header p {
  color: gray;
}
.header-right {
  padding-top: 10px;
  color: $starbucks-color;
}
.header-left{
  padding-top: 10px;
}

.no-address{
  background-color: #fff;
  text-align: center;
  color:gray
}
.common-address {

    background-color: #fff;
    margin-top: $common-margin;
    height: 70%;
    ul {
      padding-left: 0;
      li {
        border-bottom: 1px solid #ccc;
        padding-top: $common-padding;
        
      }
      li:last-child{
          border-bottom: none;
          
        }
    }
  }
  .btn {
    padding: $common-padding;
  }
  .banner{
    background-color: #fff;
    display: flex;
    justify-content: space-between;
  }
  .banner-right{
        padding-top: 15px;
  }
  .banner-left p:last-child{
    line-height: 1px;
    color:Gold;
  }
  .banner-icon{
    color:$starbucks-color
  }
  .foot{
    background-color: #fff;
    padding-top:10px;
  }
  hr{
    border-bottom:none;
    // border-top:none;
  }
 .fox{
   background-color: #fff;
 }
</style>